﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data.SqlClient;
using System.Configuration;
using ERPStudio;
using System.Threading;
using System.Globalization;
using System.Reflection;

namespace ResUma
{
    class dscModule : ModuleClass
    {

        public TreeNode ConsultaArhiva = null;   
        public dscModule(Int16 codUnit, String numeUnit,String theme):base(codUnit,numeUnit,theme)
        {
            workConnectionString = "ESRPConnectionString";
            ModuleName = "resuma";
        }
        /// <summary>
        /// returneaza ID-ul intern pentru autorizare - 
        /// deriva din numele modului si este o cheie de control
        /// </summary>
        /// <returns></returns>
        override public String GetModuleID()
        {
            return "03";
        }
       
        
        /// <summary>
        /// incarca meniul acestui modul
        /// </summary>
        /// <param name="myMenu"></param>
        new public void LoadMenu(ToolStripMenuItem mn, Form vForm, Guid appid, Guid userID)
        {
            base.LoadMenu(mn, (FrmMainMdi)vForm, appid, userID);
            //InitStoredProcedure("Init_ResUma",CodUnitate.ToString());

        }

        public void Departamente(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.DepartamenteFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmTreeRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmTreeRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Tipuri_Departamente(object sender, EventArgs e)
        {

            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.TipDepartamentFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }

            
        }

        public void Tipuri_Documente_Scanate(object sender, EventArgs e)
        {
            DocumenteScanateTipFrm frm = new DocumenteScanateTipFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }


        public void Scanare_Documente(object sender, EventArgs e)
        {
            DocumenteScanateFrm frm = new DocumenteScanateFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }
        
        public void Nomenclatoare_CaseAsigSanatate(object sender, EventArgs e)
        {
            CaseAsigSanatateFrm frm = new CaseAsigSanatateFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Gestiune_Personal(object sender, EventArgs e)
        {
            PersonalFrm frm = new PersonalFrm(this,-1);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void StatDeFunctii(object sender, EventArgs e)
        {
            StatDeFunctiiFrm frm = new StatDeFunctiiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void CalculSalarii(object sender, EventArgs e)
        {
            RecalculSalariiFrm frm = new RecalculSalariiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Nomenclatoare_Ocupatii(object sender, EventArgs e)
        {
            OcupatiiFrm frm = new OcupatiiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Nomenclatoare_TipStudii(object sender, EventArgs e)
        {
            TipStudiiFrm frm = new TipStudiiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Nomenclatoare_TipContracte(object sender, EventArgs e)
        {
            TipContracteFrm frm = new TipContracteFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Nomenclatoare_TipGrad(object sender, EventArgs e)
        {
            TipGradFrm frm = new TipGradFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Nomenclatoare_Judete(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.JudeteFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void Nomenclatoare_Localitati(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.LocalitatiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }
        }

        public void TipSpecialitati(object sender, EventArgs e)
        {
            TipSpecialitatiFrm frm = new TipSpecialitatiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void TipPrezenta(object sender, EventArgs e)
        {
            TipPrezentaFrm frm = new TipPrezentaFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void ParametrizareModul(object sender, EventArgs e)
        {
            ResUmaSetupFrm frm = new ResUmaSetupFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Pontaje(object sender, EventArgs e)
        {
            PontajFrm frm = new PontajFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void TipuriSporuri(object sender, EventArgs e)
        {
            TipSporuriFrm frm = new TipSporuriFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void TipuriRetineri(object sender, EventArgs e)
        {
            TipRetineriFrm frm = new TipRetineriFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void TipuriAdaos(object sender, EventArgs e)
        {
            TipAdaosuriFrm frm = new TipAdaosuriFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void PreluareDate(object sender, EventArgs e)
        {
            SqlConnection con = StudioForm.DeschideConexiune(workConnectionString);
            SqlCommand comm = new SqlCommand("resuma_PreluareDate", con);
            comm.CommandType = System.Data.CommandType.StoredProcedure;
            //comm.Parameters.Add(new SqlParameter(
        }

        public void TiparirePV(object sender, EventArgs e)
        {
            Procese_Verbale.OptiuniPV frm = new Procese_Verbale.OptiuniPV(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Grile(object sender, EventArgs e)
        {
            GrilaFrm frm = new GrilaFrm(this,-1);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Calculatoare(object sender, EventArgs e)
        {
            CalculatoareDetaliuFrm frm = new CalculatoareDetaliuFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void CertificateMedicale(object sender, EventArgs e)
        {
            CertificateMedicaleFrm frm = new CertificateMedicaleFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void CarteMuncaIstoric(object sender, EventArgs e)
        {
            CarteMuncaFrm frm = new CarteMuncaFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }


        public void Unitati_functionale(object sender, EventArgs e)
        {
            FrmMainMdi frm = mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;

            String numeClasa = "ERPForms.UnitatiFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                     new object[] { this }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                newFrm.MdiParent = frm;
                newFrm.Show();
            }

        }

        public void ExportDeclaratii(object sender, EventArgs e)
        {
            ExportDeclaratiiFrm frm = new ExportDeclaratiiFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Import(object sender, EventArgs e)
        {
            ImportFrm frm = new ImportFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void Resuma_Garzi(object sender, EventArgs e)
        {
            AngajatiGarziFrm frm = new AngajatiGarziFrm(this);
            frm.MdiParent = mdiForm;
            frm.Show();
        }

        public void ConsultareArhiva(object sender, EventArgs e)
        {
            if (AnArhiva == String.Empty)
            {
                FrmMainMdi frm = mdiForm as FrmMainMdi;
                Assembly asm = frm.GetModule("erpforms");
                if (asm == null)
                    return;
                String numeClasa = "ERPForms.ConsultareArhivaFrm";
                Type mModule = asm.GetType(numeClasa);

                if (mModule != null)
                {
                    FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                       new object[] { this, ConsultaArhiva }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                    newFrm.MdiParent = frm;
                    newFrm.Show();
                }

            }
            else
            {
                ToolStripMenuItem mn_Consultare_Arhiva = null;
                ToolStripMenuItem mn_Parametrizare_Modul = null;

                mn_Consultare_Arhiva = FindMenuItem(menuMain, "Consultare Arhiva");
                mn_Parametrizare_Modul = FindMenuItem(menuMain, "Setari");

                AnArhiva = String.Empty;
                mn_Consultare_Arhiva.Text = "Consultare Arhiva";
                StudioForm.SetArhiva(AnArhiva);
                mn_Parametrizare_Modul.Visible = true;
                if (ConsultaArhiva != null)
                    ConsultaArhiva.Text = "Consultare Arhiva";
            }

        }


    }
}
